using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Encryption {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void btnEncrypt_Click(object sender, EventArgs e) {
            try {
                Cryptographer crypter = new Cryptographer();
                if (this.txtKey.Text.Trim().Length > 0) {
                    crypter.setDESKey(this.txtKey.Text.Trim());
                }
                else {
                    crypter.setDESKey("leanhhuy");  
                }
                this.txtResult.Text = crypter.EncryptDES(this.txtData.Text);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnDecrypt_Click(object sender, EventArgs e) {
            try {
                Cryptographer crypter = new Cryptographer();
                if (this.txtKey.Text.Trim().Length > 0) {
                    crypter.setDESKey(this.txtKey.Text.Trim());
                }
                else {
                    crypter.setDESKey("leanhhuy");
                }
                this.txtResult.Text = crypter.DecryptDES(this.txtData.Text);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnMd5_Click(object sender, EventArgs e) {
            this.txtResult.Text = Cryptographer.hashMD5(this.txtData.Text);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
            Application.Exit();
        }

    }
}